package com.study.generator.controller;

import com.study.generator.starter.SignGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/generator")
public class UuidController {

    @Autowired
    private SignGenerator signGenerator;

    @GetMapping("/getUuid")
    public String getUuid(){
        log.info("getUuid");
        try{
            return signGenerator.getNumber().get(SignGenerator.BITS_FULL_NAME).toString();
        } catch (Exception e) {
            return "发生错误：" + e.getMessage();
        }
    }

    @GetMapping("/reverse")
    public Map<String, Long> reverse(@RequestParam("id") Long id){
        return signGenerator.reverseNumber(id);
    }
}
